import time

from selenium import webdriver
from ..exception.TestException import TestException
from ..common.ui.Selector import Selector
from .autocomplete import AutoComplete

import pytest


def test_set_value():
    browser = webdriver.Chrome()
    browser.maximize_window()
    browser.get("https://fish.iwhalecloud.com/fish-desktop/examples/autocomplete/index.html")
    time.sleep(2)
    try:
        autoComplete = AutoComplete(browser, 'tags', Selector.ID)
        autoComplete.setValue('ActionScript')
        time.sleep(2)
    finally:
        browser.close()


def test_set_value_not_exist():
    browser = webdriver.Chrome()
    browser.maximize_window()
    browser.get("https://fish.iwhalecloud.com/fish-desktop/examples/autocomplete/index.html")
    time.sleep(2)
    try:
        autoComplete = AutoComplete(browser, 'tags', Selector.ID)
        with pytest.raises(TestException):
            autoComplete.setValue('ActionScriptxxx')
    finally:
        browser.close()


if __name__ == '__main__':
    pytest.main(['-s','autocomplete_test.py'])